import 'package:flutter/material.dart';

class FieldPage extends StatefulWidget {
  FieldPage({Key key}) : super(key: key);

  @override
  _FieldPageState createState() => _FieldPageState();
}

class _FieldPageState extends State<FieldPage> {
  // 定义初始值
  var _username = new TextEditingController();
  
  @override
  void initState() {
    super.initState();
    _username.text = "初始值";
  }
  
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("Fierd.dart"),
      ),
      body: Padding(
        padding: EdgeInsets.all(20),
        child: Column(
          children: <Widget>[
            TextField(
              decoration: InputDecoration(
                hintText: "请输入用户名"
              ),
              controller: _username,
              onChanged: (value) {
                _username.text = value;
              }
            ),
            SizedBox(height: 20.0),
            Container(
              width: double.infinity,
              child: RaisedButton(
                child: Text("登录"),
                onPressed: () {
                  print(this._username.text);
                },
                color: Colors.blue,
                textColor: Colors.white,
              )
            )
          ],
        ),
      ),
    );
  }
}

class TextDemo extends StatelessWidget {
  const TextDemo({Key key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container(
      child: Column(
        children: <Widget>[
          TextField(),
          SizedBox(
            height: 20,
          ),
          TextField(
            decoration: InputDecoration(
              hintText: "请输入内容",
              border: OutlineInputBorder()
            ),
          ),
          TextField(
            // 多行文本框
            maxLines: 4,
            decoration: InputDecoration(
              hintText: "多行文本框",
              border: OutlineInputBorder()
            ),
          ),
          TextField(
            // 密码框
            obscureText: true,
            decoration: InputDecoration(
              hintText: "密码框",
              border: OutlineInputBorder()
            ),
          ),
          TextField(
            // labelText
            decoration: InputDecoration(
              border: OutlineInputBorder(),
              labelText: "用户名"
            ),
          )
        ],
      ),
    );
  }
}

